﻿using CAD.DAL;
using CAD.DAL.cajaDSTableAdapters;
using CAD.DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CAD.BLL
{
    public class cajaBLL
    {
        public static List<caja> SelectAll()
        {
            caja_selectAllTableAdapter adapter = new caja_selectAllTableAdapter();
            cajaDS.caja_selectAllDataTable dtCliente = adapter.SelectAll();
            List<caja> LISTAobjCliente = new List<caja>();
            foreach (cajaDS.caja_selectAllRow row in dtCliente)
            {
                caja objCliente = rowToDto(row);
                LISTAobjCliente.Add(objCliente);
            }
            return LISTAobjCliente;
        }
        private static caja rowToDto(cajaDS.caja_selectAllRow row)
        {
            caja objCliente = new caja();
            objCliente.Nombre = row.nombre;
            objCliente.Id = row.id;
            objCliente.Monto = row.monto;
            objCliente.Estado = row.estado;
            return objCliente;
        }
        public static caja SelectByID(int id)
        {
            caja_selectAllTableAdapter adapter = new caja_selectAllTableAdapter();
            cajaDS.caja_selectAllDataTable dtCliente = adapter.SelectByID(id);
            caja objCliente;
            try
            {
                objCliente = rowToDto(dtCliente[0]);
            }
            catch (Exception)
            {
                objCliente = null;
            }
            return objCliente;
        }
        public static void updatemonto(int idcaja, double monto)
        {
            caja_selectAllTableAdapter adapter = new caja_selectAllTableAdapter();
            adapter.updatemonto(idcaja,monto);
        }
    }
}
